<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/30
 * Time: 15:55
 */
namespace app\appmsg\controller;

use app\common\model\Appmsg;
use think\facade\Request;
use app\admin\controller\AdminBase;

class Delete extends AdminBase
{
    public function __call($action = '', $params = array())
    {
        $id = Request::param('id');
        if (!$id) {
            return '对不起，请选择您要删除的图文！';
        }

        $ids = explode(',', trim($id, ','));
        foreach ($ids as $v) {
            if (!$v) {
                return '请选择要删除的图文信息';
            }

            $info = _uri('appmsg', ['id' => $v]);
            if (!$info) {
                return '这条图文信息不存在';
            }

            if ($info['type'] == 1) {
                if (_uri('appmsg', array('relation_id'=>$v))) {
                    return ['info' => '该图文已关联到多图文，为确保多图文的完整，请先取消多图文里的关联'];
                }
            }

            Appmsg::update(array('status'=>0), ['id' => $v]);

//            if ($flag) {
//                //_model('appmsg')->update(array('merge_id'=>$v), array('status'=>0));
//            }
        }

        return ['info' => "ok"];
    }
}